(in-package :lilu-mcclim-apropos)

;;;
;;;
;;;

(clim:define-presentation-type matched-package () :inherit-from '(matched-object))

(clim:define-presentation-method clim:present (object (type matched-package) stream
                                                      (view clim:textual-view)
                                                      &key acceptably for-context-type)
  (declare (ignore acceptably for-context-type))
  (princ (package-name object) stream))

;;;
;;;
;;;


(clim:define-application-frame package-apropos-frame (iapropos-application-frame)
  ()
  (:default-initargs
   :iapropos (make-instance 'package-iapropos)
   :presentation-type 'matched-package
   :object-name "Package")
  (:command-table (package-apropos-frame-command-table
                   :inherit-from (iapropos-command-table
                                  iapropos-edit-command-table)
                   :menu (("Edit" :menu iapropos-edit-command-table)
                          ("Quit" :menu iapropos-command-table))))
  (:panes
   (package-result-display
    (make-ipropos-frame-matched-objects-pane))
   (package-output-display
    (make-ipropos-frame-selected-objects-pane))
   (package-name-regex-text-field
    (make-iapropos-frame-option-regex-pane :package-name-regex))
   (options
    (clim:vertically nil
      (clim:labelling (:label "Package")
        (clim:vertically nil
          (make-iapropos-frame-option-value-pane :nickname-p :vertical)
          (make-iapropos-frame-option-value-pane :location-p :vertical)))
      (clim:labelling (:label "Selection")
        (make-iapropos-frame-selection-type-pane :orientation :vertical))))
   (actions (clim:labelling (:label "Actions")
              (make-iapropos-frame-action-pane))))
  (:layouts
   (:default
    (clim:vertically nil
      (3/5
       (clim:horizontally nil
         (clim:vertically nil
           options
           actions
           clim:+fill+)
         (clim:labelling (:label "Results")
           package-result-display)))
      (2/5
       (clim:vertically nil
         (clim:labelling (:label "Output")
           package-output-display)
         (clim:labelling (:label "package apropos" :align-x :center)
           package-name-regex-text-field)))))))

(defun run-package-apropos (&key (new-process nil)
                              (width 790)
                              (height 550)
                              port
                              frame-manager
                              (pretty-name "Package Apropos")
                              (process-name "package-apropos-frame"))
  (run-iapropos-application-frame 'package-apropos-frame
                                  :new-process new-process
                                  :width width
                                  :height height
                                  :port port
                                  :frame-manager frame-manager
                                  :pretty-name pretty-name
                                  :process-name process-name))
